import { http } from "@/utils/http";
import { lmsUrlApi } from "../utils";

export type searchCourse = {
  name: string;
  folderId: string;
};

// 获取课程列表
export const getCourseList = (params: searchCourse) => {
  return http.request<any[]>("get", lmsUrlApi("study/courseList"), { params });
};

// 获取课程详细信息
export const getCourseDetail = (id: string) => {
  return http.request<any>("get", lmsUrlApi("study/courseDetail/" + id));
};

// 获取课程下的课件列表
export const getCoursewareDetails = (courseId: string) => {
  return http.request<any>(
    "get",
    lmsUrlApi("study/coursewareDetails/" + courseId)
  );
};

export type CoursewareDto = {
  courseware: any;
  resourceUri: string;
};

// 获取课件资源信息
export const getCoursewareResourceInfo = (
  coursewareId: string,
  courseId: string
) => {
  return http.request<any>(
    "get",
    lmsUrlApi("study/resource/" + coursewareId + "/" + courseId)
  );
};

// 获取请求url上的参数
export const getRequestParams = (key: string) => {
  const temp = window.location.href.split("?")[1];
  const pram = new URLSearchParams("?" + temp);
  return pram.get(key);
};
